
unsigned int crc_valid = 0xFFFF;

unsigned char data = 0x00;

unsigned char addr = 0xC6;

unsigned char func = 0x03;


void crc(unsigned char vData) {
  unsigned char crcHigh = highByte(crc_valid);
  unsigned char crcLow = lowByte(crc_valid);

  crc_valid = (crcHigh << 8) + (crcLow ^ vData);

  for (int i = 0; i < 8; i++)
  {
    crc_valid = crc_valid >> 1;
    Serial.println(crc_valid);

    int firstBit = bitRead(crc_valid, 0);
    Serial.println(firstBit);
    if (firstBit == 1) {
      crc_valid = crc_valid ^ 0xA001;
    }
    if (firstBit == 0)
    {
      crc_valid = crc_valid >> 1;
    }
  }
}

void setup() {
  Serial.begin(9600);
  crc(data);
}

void loop() {
  // put your main code here, to run repeatedly:

}
